package push{
/**
 * @author daichangxin
 */
public class UserInfoSubject implements IUserInfoSubject
{
	private var _observerList:Array = [];
	
	private var _userName:String;
	private var _level:uint;
	private var _golden:uint;
	
	public function UserInfoSubject()
	{
		
	}
	
	/**
	 * 模拟设置数据
	 */
	public function setData(obj:Object):void
	{
		this._userName = obj.userName;
		this._level = obj.level;
		this._golden = obj.golden;
		
		//数据发生变化 通知观察者
		notifyObservers();
	}
	
	public function registerObserver(o : IUserInfoObserver) : void
	{
		if (_observerList.indexOf(o) > -1) return;
		
		_observerList.push(o);
	}

	public function removeObserver(o : IUserInfoObserver) : void
	{
		var index:int = _observerList.indexOf(o);
		if (index > -1)
		{
			_observerList.splice(index, 1);
		}
	}

	public function notifyObservers() : void
	{
		for each (var observer : IUserInfoObserver in _observerList) 
		{
			observer.update(this._userName, this._level, this._golden);
		}
	}
}
}
